{#
This file is part of EC-CUBE

Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.

http://www.ec-cube.co.jp/

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}
<script>
    $('.set-customer').on('click', function() {
        $.ajax({
            url: '{{ url('admin_order_search_customer_by_id') }}',
            type: 'POST',
            dataType: 'json',
            data: {'id': this.dataset.customer}
        }).done(function(data) {
            // 顧客情報をフォームにセットする.
            $('#order_CustomerId').html(data['id']);
            $('#order_Customer').val(data['id']);
            $('#order_name_name01').val(data['name01']);
            $('#order_name_name02').val(data['name02']);
            $('#order_kana_kana01').val(data['kana01']);
            $('#order_kana_kana02').val(data['kana02']);
            $('#order_postal_code').val(data['postal_code']);
            $('#order_address_pref').val(data['pref']);
            $('#order_address_addr01').val(data['addr01']);
            $('#order_address_addr02').val(data['addr02']);
            $('#order_email').val(data['email']);
            $('#order_phone_number').val(data['phone_number']);
            $('#order_company_name').val(data['company_name']);
            // モーダルを閉じる.
            $('#searchCustomerModal').modal('hide');
        }).fail(function(data) {
            alert('search customer(by id) failed.');
        });
    });

    // 会員検索
    $('#customer_pagination a').on('click', function(event) {
        if (!$(this).parent().is('.active')) {
            var list = $('#searchCustomerModalList');
            list.children().remove();

            $.ajax({
                url: $(this).attr('href'),
                type: 'GET',
                dataType: 'html'
            }).done(function(data) {
                $('#searchCustomerModalList').html(data);
            }).fail(function(data) {
                alert('search customer failed.');
            });
        }
        event.preventDefault();
    });
</script>

<table class="table table-striped">
    <thead class="table-active">
    <tr>
        <th class="pt-2 pb-2 pl-3">{{ 'admin.common.id'|trans }}</th>
        <th class="pt-2 pb-2">{{ 'admin.common.name'|trans }}</th>
        <th class="pt-2 pb-2">{{ 'admin.common.phone_number'|trans }}</th>
        <th class="pt-2 pb-2">{{ 'admin.common.mail_address'|trans }}</th>
        <th class="pt-2 pb-2 pl-5">&nbsp;</th>
    </tr>
    </thead>
    <tbody>
    {% for Customer in data %}
        <tr>
            <td class="text-center"><span>{{ Customer.id }}</span></td>
            <td><span>{{ Customer.name }}</span></td>
            <td><span>{{ Customer.phone_number }}</span></td>
            <td><span>{{ Customer.email }}</span></td>
            <td>
                <div class="row justify-content-end pr-2">
                    <button type="button" class="btn btn-ec-actionIcon set-customer" data-customer="{{ Customer.id }}"><i class="fa fa-plus fa-lg text-secondary" aria-hidden="true"></i></button>
                </div>
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>
{% if pagination.totalItemCount > 0 %}
    <div id="customer_pagination" class="row justify-content-md-center mb-4">
        {% include '@admin/pager.twig' with {'pages': pagination.paginationData, 'routes': 'admin_order_search_customer_html_page'} %}
    </div>
{% endif %}
